home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / misc / dialoglib.lha / vcons.c < prev    next >
C/C++ Source or Header  |  1993-03-06  |  8KB  |  303 lines

  1. #include <clib/macros.h>
  2. #include <proto/utility.h>
  3. #include "dialog.h"
  4. #ifdef DEBUG1
  5.     #include <stdio.h>
  6. #endif
  7.  
  8. /* filters for structure flag common among car and cdr */
  9. static ULONG getVConsStructure( DialogElement *de )
  10. {
  11.     DialogElement *car, *cdr;
  12.     ULONG vstructure = DESF_VBaseline;
  13.  
  14.     if( !de )
  15.         return 0;
  16.  
  17.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  18.         vstructure &= getDialogElementStructure( car );
  19.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  20.         vstructure &= getDialogElementStructure( cdr );
  21.  
  22.     return vstructure | DESF_HBaseline;
  23. }
  24.  
  25. static VOID setupVCons( DialogElement *de )
  26. {
  27.     DialogElement *car, *cdr;
  28.     LONG alignment, minleft, minright, minwidth, maxleft, maxright, maxwidth;
  29.     ULONG substructure;
  30.  
  31.     if( !de )
  32.         return;
  33.  
  34.     alignment = GetTagData( DA_Alignment, 0, de->taglist );    /* currently unused */
  35.  
  36.     /* determine structure */
  37.     de->structure = getDialogElementStructure( de );
  38.  
  39.     /* these value are modified later */
  40.     setMinTopExtent( de, 0 );
  41.     setMaxTopExtent( de, 0 );
  42.     setMinBottomExtent( de, 0 );
  43.     setMaxBottomExtent( de, 0 );
  44.     if( de->structure & DESF_VBaseline )
  45.     {
  46.         setMaxLeftExtent( de, 0 );
  47.         setMaxRightExtent( de, 0 );
  48.     }
  49.     else
  50.         setMaxWidth( de, 0 );
  51.  
  52.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  53.     {
  54.         setupDialogElement( car );
  55.         de->idcmp_mask |= car->idcmp_mask;
  56.         substructure = getDialogElementStructure( car );
  57.  
  58.         /* modify Min/MaxTopExtent to accomodate car */
  59.         if( substructure & DESF_HBaseline )
  60.         {
  61.             setMinTopExtent( de, getMinTopExtent( car ) + getMinBottomExtent( car ) );
  62.             setMaxTopExtent( de, getMaxTopExtent( car ) + getMaxBottomExtent( car ) );
  63.         }
  64.         else
  65.         {
  66.             setMinTopExtent( de, getMinHeight( car ) );
  67.             setMaxTopExtent( de, getMaxHeight( car ) );
  68.         }
  69.  
  70.         /* modify Min/MaxWidth or Min/MaxLeft/RightExtent to accomodate car */
  71.         if( substructure & DESF_VBaseline )
  72.         {
  73.             minleft = getMinLeftExtent( car );
  74.             minright = getMinRightExtent( car );
  75.             maxleft = getMaxLeftExtent( car );
  76.             maxright = getMaxRightExtent( car );
  77.             if( de->structure & DESF_VBaseline )
  78.             {
  79.                 if( minleft > getMinLeftExtent( de ) )
  80.                     setMinLeftExtent( de, minleft );
  81.                 if( minright > getMinRightExtent( de ) )
  82.                     setMinRightExtent( de, minright );
  83.                 if( maxleft > getMaxLeftExtent( de ) )
  84.                     setMaxLeftExtent( de, maxleft );
  85.                 if( maxright > getMaxRightExtent( de ) )
  86.                     setMaxRightExtent( de, maxright );
  87.             }
  88.             else
  89.             {
  90.                 minwidth = minleft + minright;
  91.                 maxwidth = maxleft + maxright;
  92.                 if( minwidth > getMinWidth( de ) )
  93.                     setMinWidth( de, minwidth );
  94.                 if( maxwidth > getMaxWidth( de ) )
  95.                     setMaxWidth( de, maxwidth );
  96.             }
  97.         }
  98.         else
  99.         {
  100.             minwidth = getMinWidth( car );
  101.             maxwidth = getMaxWidth( car );
  102.             if( minwidth > getMinWidth( de ) )
  103.                 setMinWidth( de, minwidth );
  104.             if( maxwidth > getMaxWidth( de ) )
  105.                 setMaxWidth( de, maxwidth );
  106.         }
  107.     }
  108.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  109.     {
  110.         setupDialogElement( cdr );
  111.         de->idcmp_mask |= cdr->idcmp_mask;
  112.         substructure = getDialogElementStructure( cdr );
  113.  
  114.         /* modify Min/MaxBottomExtent to accomodate cdr */
  115.         if( substructure & DESF_HBaseline )
  116.         {
  117.             setMinBottomExtent( de, getMinTopExtent( cdr ) + getMinBottomExtent( cdr ) );
  118.             setMaxBottomExtent( de, getMaxTopExtent( cdr ) + getMaxBottomExtent( cdr ) );
  119.         }
  120.         else
  121.         {
  122.             setMinBottomExtent( de, getMinHeight( cdr ) );
  123.             setMaxBottomExtent( de, getMaxHeight( cdr ) );
  124.         }
  125.  
  126.         /* modify Min/MaxWidth or Min/MaxLeft/RightExtent to accomodate cdr */
  127.         if( substructure & DESF_VBaseline )
  128.         {
  129.             minleft = getMinLeftExtent( cdr );
  130.             minright = getMinRightExtent( cdr );
  131.             maxleft = getMaxLeftExtent( cdr );
  132.             maxright = getMaxRightExtent( cdr );
  133.             if( de->structure & DESF_VBaseline )
  134.             {
  135.                 if( minleft > getMinLeftExtent( de ) )
  136.                     setMinLeftExtent( de, minleft );
  137.                 if( minright > getMinRightExtent( de ) )
  138.                     setMinRightExtent( de, minright );
  139.                 if( maxleft > getMaxLeftExtent( de ) )
  140.                     setMaxLeftExtent( de, maxleft );
  141.                 if( maxright > getMaxRightExtent( de ) )
  142.                     setMaxRightExtent( de, maxright );
  143.             }
  144.             else
  145.             {
  146.                 minwidth = minleft + minright;
  147.                 maxwidth = maxleft + maxright;
  148.                 if( minwidth > getMinWidth( de ) )
  149.                     setMinWidth( de, minwidth );
  150.                 if( maxwidth > getMaxWidth( de ) )
  151.                     setMaxWidth( de, maxwidth );
  152.             }
  153.         }
  154.         else
  155.         {
  156.             minwidth = getMinWidth( cdr );
  157.             maxwidth = getMaxWidth( cdr );
  158.             if( minwidth > getMinWidth( de ) )
  159.                 setMinWidth( de, minwidth );
  160.             if( maxwidth > getMaxWidth( de ) )
  161.                 setMaxWidth( de, maxwidth );
  162.         }
  163.     }
  164. }
  165.  
  166. static ULONG layoutVCons( DialogElement *de, LayoutMessage *lm )
  167. {
  168.     DialogElement *car, *cdr;
  169.     LayoutMessage message;
  170.     LONG alignment;
  171.     LONG y, top, bottom, white, spare;
  172.     ULONG substructure, error = DIALOGERR_OK;
  173.  
  174.     if( !de )
  175.         return DIALOGERR_BAD_ARGS;
  176.     if( !lm )
  177.         return DIALOGERR_BAD_ARGS;
  178.  
  179. #ifdef DEBUG1
  180.     printf(
  181.     "layoutVCons : x %d, y %d, width %d, height %d, left %d, right %d, top %d, bottom %d\n",
  182.         lm->lm_X, lm->lm_Y, lm->lm_Width, lm->lm_Height,
  183.         lm->lm_Left, lm->lm_Right, lm->lm_Top, lm->lm_Bottom );
  184. #endif
  185.  
  186.     alignment = GetTagData( DA_Alignment, 0, de->taglist );    /* currently ignored */
  187.  
  188.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  189.     {
  190.         substructure = prepareMemberLayoutH( &message, de, car, lm );
  191.         y = lm->lm_Y;
  192.         if( substructure & DESF_HBaseline )
  193.         {
  194.             LONG mintop, minbottom;
  195.  
  196.             mintop = getMinTopExtent( car );
  197.             minbottom = getMinBottomExtent( car );
  198.             white = lm->lm_Top - mintop - minbottom;
  199.             top = getMaxTopExtent( car ) - mintop;
  200.             bottom = getMaxBottomExtent( car ) - minbottom;
  201.             spare = top + bottom;
  202.             top = mintop + ( ( spare ) ? ( top * white ) / spare : 0 );
  203.             bottom = minbottom + ( ( spare ) ? ( bottom * white ) / spare : 0 );
  204.             prepareLayoutHBaseline( &message, top, bottom );
  205.             y -= bottom;
  206.         }
  207.         else
  208.         {
  209.             prepareLayoutNoHBaseline( &message, lm->lm_Top );
  210.             y -= lm->lm_Top;
  211.         }
  212.         prepareLayoutY( &message, y );
  213.         error = layoutDialogElement( car, &message, lm->lm_PreviousPtr );
  214.         if( error )
  215.             goto termination;
  216.     }
  217.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  218.     {
  219.         substructure = prepareMemberLayoutH( &message, de, cdr, lm );
  220.         y = lm->lm_Y;
  221.         if( substructure & DESF_HBaseline )
  222.         {
  223.             LONG mintop, minbottom;
  224.  
  225.             mintop = getMinTopExtent( cdr );
  226.             minbottom = getMinBottomExtent( cdr );
  227.             white = lm->lm_Bottom - mintop - minbottom;
  228.             top = getMaxTopExtent( cdr ) - mintop;
  229.             bottom = getMaxBottomExtent( cdr ) - minbottom;
  230.             spare = top + bottom;
  231.             top = mintop + ( ( spare ) ? ( top * white ) / spare : 0 );
  232.             bottom = minbottom + ( ( spare ) ? ( bottom * white ) / spare : 0 );
  233.             prepareLayoutHBaseline( &message, top, bottom );
  234.             y += top;
  235.         }
  236.         else
  237.             prepareLayoutNoHBaseline( &message, lm->lm_Bottom );
  238.         prepareLayoutY( &message, y );
  239.         error = layoutDialogElement( cdr, &message, lm->lm_PreviousPtr );
  240.         if( error )
  241.             goto termination;
  242.     }
  243. termination:
  244.     return error;
  245. }
  246.  
  247. static DialogElement *matchVCons( DialogElement *de, MatchMessage *mm )
  248. {
  249.     DialogElement *car, *cdr, *match = NULL;
  250.  
  251.     if( !de )
  252.         return NULL;
  253.     if( !mm )
  254.         return NULL;
  255.  
  256.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  257.         if( match = mapDialogEvent( car, mm->mm_IntuiMsg ) )
  258.             goto termination;
  259.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  260.         if( match = mapDialogEvent( cdr, mm->mm_IntuiMsg ) )
  261.             goto termination;
  262. termination:
  263.     return match;
  264. }
  265.  
  266. static VOID clearVCons( DialogElement *de )
  267. {
  268.     DialogElement *car, *cdr;
  269.  
  270.     if( !de )
  271.         return;
  272.  
  273.     if( car = (DialogElement *)GetTagData( DA_CAR, 0, de->taglist ) )
  274.         clearDialogElement( car );
  275.     if( cdr = (DialogElement *)GetTagData( DA_CDR, 0, de->taglist ) )
  276.         clearDialogElement( cdr );
  277. }
  278.  
  279. ULONG dispatchVCons( struct Hook *hook, DialogElement *de, DialogMessage *dm )
  280. {
  281.     ULONG result;
  282.  
  283.     switch( dm->dm_MethodID )
  284.     {
  285.     case DIALOGM_GETSTRUCT:
  286.         result = getVConsStructure( de );
  287.         break;
  288.     case DIALOGM_SETUP:
  289.         setupVCons( de );
  290.         break;
  291.     case DIALOGM_LAYOUT:
  292.         result = layoutVCons( de, (LayoutMessage *)dm );
  293.         break;
  294.     case DIALOGM_MATCH:
  295.         result = (ULONG)matchVCons( de, (MatchMessage *)dm );
  296.         break;
  297.     case DIALOGM_CLEAR:
  298.         clearVCons( de );
  299.         break;
  300.     }
  301.     return result;
  302. }
  303.